package com.wuqi.dev.mvc.presenter;

import com.wuqi.dev.mvc.entity.GankEntity;
import com.wuqi.dev.mvc.http.HttpManager;
import com.wuqi.dev.mvc.model.GankModel;
import com.wuqi.dev.mvc.model.IModel;
import com.wuqi.dev.mvc.ui.IView;

/**
 * Created by Risky57 on 2017/4/19.
 */

public class Presenter {
    // 会持有M层和V层的引用
    private IView view;
    private IModel model;

    public Presenter (IView view) {
        this.view = view;
        model = new GankModel();
    }

    public void startRequest(String url){
        view.showDialog();
        model.startRequest(url, new HttpManager.OnRequestFinishedListener() {
            @Override
            public void onFinished (GankEntity gank) {
                view.dismissDialog();
                view.success(gank);
            }

            @Override
            public void onFailed (Throwable ex) {
                view.dismissDialog();
                view.failed(ex);
            }
        });
    }

}
